package com.guanyong.webapi.handle;



import com.guanyong.model.UserBaseModel;
import com.guanyong.services.UserBaseService;
import com.guanyong.utils.Comm.ResultObject;
import com.guanyong.utils.NetUtils.CookieUtils;
import com.guanyong.utils.UniqueID.LoginTokenID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Eric.Zhang on 2017/4/12.
 */
@Service
public class UserHandle {



    @Autowired
    UserBaseService userBaseService;
    @Autowired
    TokenHelper tokenHelper;
    /**
     * 在缓存中获取一个用户
     * @param uid
     * @return
     */

     /**
     *  获取当前访问用户
     * @param request
     * @return
     */
    public UserBaseModel getCurUser(HttpServletRequest request){
        ResultObject<LoginTokenID> loginTokenID=tokenHelper.getToken(request);
        if(loginTokenID==null||loginTokenID.getResult()==null){
            return null;
        }else{
            Integer temp =tokenHelper.exsitToken(loginTokenID.getResult().getUid(),loginTokenID.getResult().getUniqueObjectID().toString());
            if (temp!=1){
                return null;
            }else{
                return userBaseService.getUserModel(loginTokenID.getResult().getUid(),1);
            }
//            return userBaseService.getUserModel(loginTokenID.getResult().getUid(),1);
        }
    }

}
